// formPackage/pages/checkOrManger/agentCheckDetail/agentCheckDetail.js

import { checkAdviserEnterAction, queryCheckAdviserDetail } from "../../../../service/platform_service"
import debounce from "../../../../tools/debounce"
let app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeStyle: "",
    isShowCommentPop: false,
    checkData: {
      "adviserId": 0,
      "isPass": false,
      "remark": "",//拒绝的理由

    },
    detailId: null,
    formData: {},
    payInfo: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      detailId: options.id,
      'checkData.adviserId': options.id
    })
    this.queryCheckAdviserDetail();
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.themeStyle) {
      this.setData({
        themeStyle: app.globalData.themeStyle
      })
    }
  },
  //查询审核详情:
  queryCheckAdviserDetail() {
    wx.showLoading();
    queryCheckAdviserDetail(this.data.detailId).then(res => {
      wx.hideLoading();
      console.log("JJLog:查询到的详情是:" + JSON.stringify(res));
      if (res.code == 200) {
        this.setData({
          formData: res.data.data,
          payInfo: res.data.payInfo
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "查询失败",
        icon: "none"
      })
      console.error("JJLog:queryCheckAdviserDetail", err);
    })
  },



  //预览图片:
  previewImgAction(e) {
    let url = e.currentTarget.dataset.url
    let urls = [url];
    wx.previewImage({
      current: url,
      urls: urls,
    })
  },

  submitInfoAction(e) {
    let isPass = e.currentTarget.dataset.ispass;
    this.setData({
      'checkData.isPass': isPass
    })

    if (isPass) {
      //通过审核:
      wx.showModal({
        title: '提示',
        content: '确认资料通过审核',
        confirmColor: "#FF0000",
        success: res => {
          if (res.confirm) {
            this.submitInfoRequest();
          }
        }
      })

    } else {
      //拒绝报备
      this.setData({
        isShowCommentPop: true
      })
    }
  },

  //不通过理由发送:
  commentSend(e) {
    console.log(e);
    let content = e.detail.comment;
    this.setData({
      'checkData.remark': content,
      isShowCommentPop: false
    })
    this.submitInfoRequest();
  },

  //提交审核:
  //提交审核结果
  submitInfoRequest() {
    wx.showLoading();
    console.log("JJLog:审核提交参数:" + JSON.stringify(this.data.checkData));
    let { adviserId, isPass, remark } = this.data.checkData
    checkAdviserEnterAction(adviserId, isPass, remark).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        wx.showToast({
          title: "提交成功",
          icon: "success"
        })
        setTimeout(() => {
          wx.navigateBack({
            delta: 0,
          })
        }, 2000)
      }
    }).catch(err => {
      console.error("JJLog:checkAdviserEnterAction", err);
      wx.hideLoading();
      wx.showToast({
        title: err || "审核失败",
        icon: "none"
      })
    })
  },




  hideCommentPop() {
    this.setData({
      isShowCommentPop: false
    })
  },

})